<template>
	<view>
		<!-- <button @click="open">打开弹窗</button> -->
		<u-popup ref="popup" :show="show" type="bottom" background-color="#fff" border-radius="10px 10px 0 0"
			round="20rpx">
			<view>
				<view class="sxtext">
					<text>筛选</text>
					<u-icon name="close" @click="onclose"></u-icon>
				</view>
				<!-- {{ searchinputs }} -->
				<formz ref="formz" :inputs="searchinputs" :data="fromdata"></formz>
				<view style="height: 30vh"></view>
				<view class="btnbox">
					<u-button type="primary" text="确定" @click="onsave"></u-button>
				</view>
			</view>
		</u-popup>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				show: false,
				searchinputs: [],
				fromdata: {},
				callback: () => {},
			};
		},
		props: {
			searchdata: {
				type: Object,
				default: () => {
					return {};
				},
			},
		},
		methods: {
			open(searchinputs) {
				this.fromdata = {
					...this.searchdata,
				};
				// 通过组件定义的ref调用uni-popup方法 ,如果传入参数 ，type 属性将失效 ，仅支持 ['top','left','bottom','right','center']
				this.searchinputs = searchinputs;
				this.show = true;

				let promise = new Promise((resolve, reject) => {
					this.callback = function(resolvedata, rejectdata) {
						if (resolvedata) {
							resolve(resolvedata);
						} else {
							reject(rejectdata);
						}
					};
				});
				return promise;
			},
			onclose() {
				this.show = false;
			},
			async onsave() {
				let data = await this.$refs.formz.validate();
				this.callback(data);
				this.show = false;
			},
		},
	};
</script>
<style lang="scss" scoped>
	.sxtext {
		display: flex;
		padding: 0 20rpx;
		height: 80rpx;
		align-items: center;
		justify-content: space-between;
		font-size: 32rpx;
		font-weight: bold;
	}

	.btnbox {
		padding: 20rpx 40rpx;
	}
</style>